<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo控制台</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mdui@latest/dist/css/mdui.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <style>
        .container {
            max-width: 600px;
            margin: 40px auto;
        }
    </style>
</head>
<body class="mdui-appbar-with-toolbar">

    <?php
    session_start();
    if (!isset($_SESSION['user_id'])) {
        header('Location: index.html');
        exit();
    }

    require 'db.php';

    $stmt = $pdo->prepare('SELECT username, id FROM users WHERE id = ?');
    $stmt->execute([$_SESSION['user_id']]);
    $user = $stmt->fetch();
    ?>

    <div class="container">
        <div class="mdui-card">
            <div class="mdui-card-content">
                <h2>欢迎，<?php echo htmlspecialchars($user['username']); ?>！</h2>
                <p>你的ID：<?php echo htmlspecialchars($user['id']); ?></p>

                <b>更改密码</b>
                <form action="update_password.php" method="POST" class="mdui-form">
                    <div class="mdui-textfield">
                        <label class="mdui-textfield-label">新的密码</label>
                        <input class="mdui-textfield-input" type="password" name="new_password" required>
                    </div>
                    <button class="mdui-btn mdui-btn-raised mdui-color-theme" type="submit">更新密码</button>
                </form>

                <h3 style="margin-top: 20px;"><a href="logout.php" class="mdui-btn mdui-btn-raised mdui-color-red">注销登录</a></h3>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/mdui@latest/dist/js/mdui.min.js"></script>
</body>
</html>
